// pages/orderDetail/index.js
// 采购订单列表页
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tableList: [1, 2, 3, 4, 5],
    option2: [
      { text: '默认排序', value: 'a' },
      { text: '好评排序', value: 'b' },
      { text: '销量排序', value: 'c' },
    ],
    orderState:[
      { text: '全部', value: '',icon:'' },
      { text: '待接单', value: '0',icon:'' },
      { text: '已接单待发货', value: '1',icon:'' },
      { text: '已出库发货', value: '2',icon:'' },
      { text: '已收货', value: '3',icon:'' },
      { text: '已结款', value: '4',icon:'' }
    ],
    queryParams: {
      orderState:''
    },
    orderStateValue:'',
    page:0,
    size:10,
    totalPage: 0, // 总页数
    pullFlag: false, // 是否向上拉动到底部
	  tableList: [],
	  listTip: '上拉加载更多'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
this.getList()
  },
/**
   * 待接单单列表
   */
  getList(){
    let that=this
    wx.$req({
      url: '/wms/orderSail/receiveList?page='+this.data.page+'&size='+this.data.size,
      method:'POST',
      data: {...this.data.queryParams},
      loadingText: '加载中...'
    }).then(res => {
        let procurementData=res.data.content
        let totalPage = Math.ceil(res.data.totalElements / 10)
        let rows = this.data.procurementData
        if (totalPage == 1 || this.data.totalPage === totalPage ) {
          this.setData({ listTip: '暂无更多' })
        } else {
          this.setData({ listTip: '上拉加载更多' })
        }
        if (totalPage == 0) {
          this.setData({ listTip: '暂无内容' })
        }
         // 列表数据：为true 则需要push, false，则直接覆盖
      if (this.data.pullFlag) {
        rows.push(...res.data.content)
      } else {
        rows = res.data.content
      }
        that.setData({
          procurementData: rows 
        })

      }).finally(() => { wx.stopPullDownRefresh() })
  },
  onChangeState(event){
    console.log('当前下拉项的索引：', event.detail);
    console.log(this.data.orderStateValue)
    this.setData({
      queryParams: {
        orderState:event.detail
      }
    })
    this.getList()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.onLoad()
  },
/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {
		this.setData({ 
      pullFlag: false,
      page: 0,
      size: 10
		})
		this.getList()
	},
	
 /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    let  pageNum=this.data.page
    let  pageSize=this.data.size
    if (pageNum < this.data.totalPage) {
      pageNum += 1
      this.setData({  
        pullFlag: true,
        page: pageNum,
        size: pageSize
      })
      this.getList()
    }
  },
// 跳转详情
  toInfo (e) {
    let item=e.currentTarget.dataset.item
    wx.navigateTo({
      url: '/pages/productOrderInfo/index?id='+item.id
    })
  },
  toRev () {
    wx.navigateTo({
      url: '/pages/productRev/index'
    })
  },
  toAdd () {
    wx.navigateTo({
      url: '/pages/addProductOrder/index'
    })
  }
})